import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:getwidget/colors/gf_color.dart';
import 'package:getwidget/components/radio/gf_radio.dart';
import 'package:getwidget/types/gf_radio_type.dart';

class EPRadioListTile extends StatefulWidget {
  final Function(bool arg)? onChanged;
  final double defaultFontSize;
  final double commonWH;
  final bool isSelect;

  const EPRadioListTile({
    super.key,
    this.commonWH = 14.6,
    required this.onChanged,
    required this.isSelect,
    this.defaultFontSize = EdgeConstant.edge146,
  });

  @override
  State<EPRadioListTile> createState() => _EPRadioListTileState();
}

class _EPRadioListTileState extends State<EPRadioListTile> {
  bool isSelect = false;

  @override
  void initState() {
    super.initState();
    isSelect = widget.isSelect;
  }

  void trigger() {
    isSelect = !isSelect;
    setState(() {});
    if (widget.onChanged != null) {
      widget.onChanged!(isSelect);
    }
  }

  // @override
  // void didUpdateWidget(covariant EPRadioListTile oldWidget) {
  //   super.didUpdateWidget(oldWidget);
  //   isSelect = widget.isSelect;
  // }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        trigger();
      },
      behavior: HitTestBehavior.opaque,
      child: Container(
        padding: const EdgeInsets.only(right: 10),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(
              width: widget.commonWH,
              height: widget.commonWH,
              child: GFRadio(
                size: widget.commonWH,
                value: true,
                groupValue: isSelect,
                radioColor: Colors.white,
                activeBgColor: ColorConstant.black20,
                inactiveBorderColor: const Color.fromRGBO(0, 0, 0, 0.15),
                activeBorderColor: const Color.fromRGBO(0, 0, 0, 0.15),
                type: GFRadioType.custom,
                activeIcon: const Icon(
                  Icons.check,
                  size: 12,
                  color: GFColors.WHITE,
                ),
                onChanged: (value) {
                  trigger();
                },
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(left: EdgeConstant.edge3_6),
              child: Text(
                S.current.Default,
                style: TextStyle(
                    color: Colors.black,
                    fontSize: widget.defaultFontSize,
                    letterSpacing: TextConstant.letterSpacing),
              ),
            )
          ],
        ),
      ),
    );
  }
}
